﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using MySQLStudio.DataAccess;
using System.Data;
using MySQLStudio.Common;

namespace MySQLStudio.BusinessLogic
{
    public class CollationController
    {
        public static StringCollection GetCollations(string connectionString)
        {
            string sqlQuery = InformationSchemaHelper.GetCollationsCommand();
            IDataReader reader = null;
            StringCollection collations = new StringCollection();

            try
            {
                reader = MySqlDataAccess.ExecuteDataReader(connectionString, sqlQuery);

                while (reader.Read())
                {
                    collations.Add(Convert.ToString(reader["COLLATION_NAME"]));
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ErrorMessages.InformationSchema_Failed_to_extract_collations, ex);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }

            return collations;
        }
    }
}
